package com.juc.executors.executors1;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Run1 {
    /**
     * newCachedThreadPool() 方法创建的是无界限的线程池，可以进行线程自动回收。
     * 所谓“无界线程池”就是池中存放的线程个数是理论上Integer.MAX_VALUE最大值
     * 
     */
	public static void main(String[] args) {
		  ExecutorService executorService =   Executors.newCachedThreadPool();
		  executorService.execute(new Runnable() {
			
			@Override
			public void run() {
				
				try {
					System.out.println("Runable1 begin " + System.currentTimeMillis());
					Thread.sleep(1000);
					System.out.println("A");
					System.out.println("Runable1 end " + System.currentTimeMillis());

				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		 executorService.execute(new Runnable() {
			
			@Override
			public void run() {
				try {
					System.out.println("Runable2 begin " + System.currentTimeMillis());
					Thread.sleep(1000);
					System.out.println("B");
					System.out.println("Runable2 end " + System.currentTimeMillis());

				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
	}
}
